<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">{{statistics.title}}</block>
		</cu-custom>

		<view class="cu-bar">
			<view class="action">
				当月有{{statistics.persum}}人{{statistics.title}}
			</view>
		</view>

		<view class="cu-list menu-avatar">
			<view class="cu-item" @click="goPersonDetail(item)" v-for="(item,index) in personlist" v-bind:key="index">
				<view class="cu-avatar round lg" :style="'background-image:url('+item.personphoto+');'"></view>
				<view class="content">
					<view class="text-grey">{{item.personname}}</view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">
							<!-- <text class="cuIcon-infofill text-red  margin-right-xs"></text> -->
							{{item.departname}}
						</view>
					</view>
				</view>
				<view class="action">
					<view class="text-grey text-xs">{{item.sumtime}}</view>
					<!-- <view class="cu-tag round bg-grey sm">5</view> -->
				</view>
			</view>
		</view>
		<uni-load-more :status="status" :size="5" :content-text="contentText" />
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	let _self = null
	export default {
		components: {
			uniLoadMore,
		},
		data() {
			return {
				statistics: {},
				personlist: [],
				page: 1,
				rows: 10,
				totalpage: 0,
				reload: false, //是否重新加载
				status: 'more',
				contentText: {
					// contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '到底了'
				}
			}
		},
		onLoad(options) {
			_self = this
			if (typeof(options.data) != 'undefined') {
				_self.statistics = JSON.parse(options.data)
				// console.log(this.statistics)
				_self.getData()
			}
		},
		onReachBottom() {
			if (_self.status == 'noMore') return
			_self.status = 'more'
			_self.getData()
		},
		methods: {
			goPersonDetail(item) {
				// console.log(item)
				let data = {
					personname: item.personname,
					perid: item.perid,
					date: _self.statistics.date
				}
				uni.navigateTo({
					url: `../monthly-statistics-person-detail/monthly-statistics-person-detail?data=${JSON.stringify(data)}`
				})
			},
			getData() {
				if (this.page > 1) {
					//说明已有数据，目前处于上拉加载
					this.status = 'loading';
				}
				uni.request({
					url: _self.$constant.BASEURL + _self.$constant.GET_MONTHY_STATISTICS_PERSON,
					method: "POST",
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						username: getApp().globalData.username,
						token: getApp().globalData.token,
						orgcode: getApp().globalData.orgcode,
						ymonth: _self.statistics.date,
						page: _self.page,
						rows: _self.rows,
						typeatt: _self.statistics.id
					},
					success: (res) => {
						//跳转到登陆页面	
						// console.log(res.data)
						let page = res.data.data
						// console.log(page)
						if (page.page * page.rows >= page.total) {
							_self.status = 'noMore';
						}
						if (res.data.code == 0) {
							let list = page.results
							// if(typeof(data)=='undefined') return
							let personlist = []
							list.forEach(function(item) {
								// console.log(item)
								let sumtime = ''
								switch (_self.statistics.id) {
									case 'attcount':
									sumtime = item.attdays+'天'
										break;
									case 'late':
									sumtime = item.late + '分钟'
										break;
									case 'leaveearly':
									sumtime = item.leaveearly + '分钟'
										break;
									case 'absenteeism':
									sumtime = item.absenteeismdays + '天'
										break;
									case 'leavhourss':
									sumtime = item.leavhourss + '小时'
										break;
									default:
										break;
								}
								personlist.push({
									perid: item.perid,
									personname: item.facewhitelist.personname,
									personphoto: item.facewhitelist.personphoto,
									departname: item.facewhitelist.depart.departname,
									sumtime: sumtime
								})
							})
							_self.personlist = _self.reload ? personlist : _self.personlist.concat(personlist)
							_self.page++;
							_self.reload = false;
							// console.log(list)
						} else {
							uni.showModal({
								content: res.data.message,
								showCancel: false
							})
						}
					}
				});
			}
		}
	}
</script>

<style>

</style>
